package com.health.income.remote.feign.factory;

import com.health.common.core.domain.R;
import com.health.common.domain.Department;
import com.health.common.domain.PmsMedic;
import com.health.income.remote.feign.RemoteIncomeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 服务降级处理
 *
 * @author ruoyi
 */
@Component
public class RemoteIncomeFallbackFactory implements FallbackFactory<RemoteIncomeService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteIncomeFallbackFactory.class);

    @Override
    public RemoteIncomeService create(Throwable throwable)
    {
        log.error("科室服务调用失败:{}", throwable.getMessage());
        return new RemoteIncomeService()
        {
            @Override
            public R<List<Department>> getDepartment() {
                System.out.println("\"获取部门失败:\" + throwable.getMessage()");
                return R.fail("获取部门失败:" + throwable.getMessage());
            }

            @Override
            public R<List<PmsMedic>> getMedicList(PmsMedic pmsMedic) {
                System.out.println("\"获取医生失败:\" + throwable.getMessage()");
                return R.fail("获取医生失败:" + throwable.getMessage());
            }
        };
    }
}
